package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo6 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();

        //Method m = cls.getMethod("hh");//编译正常运行错误
        Method m = cls.getDeclaredMethod("hh");//IllegalAccessException
        m.setAccessible(true);//暴力反射，强行打开访问权限
        m.invoke(obj);
        m.setAccessible(false);//调用完后尽量还原权限
    }
}
